#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int T;
int n;
int tag[N];
int cnt;
int ans;
signed main(){
    freopen("arean.in","r",stdin);
    freopen("arean.out","w",stdout);
    cin>>T;
    while(T--){
        ans = 0;
        for(int i = 1;i<=n;i++)
            tag[i] = 0;
        cin>>n;
        for(int i = 1;i<=n;i++){
            cin>>cnt;
            tag[cnt]++;
        }
        for(int i = 1;i<=n;i++)
            if(tag[i] > 1)
                ans+=tag[i]*i-i;
        cout<<ans<<endl;

    }
    return 0;

}
/*Hello Hello CCF!
                       x  y  z   res
                    |  1  1  1 | 11 |
                    |  1  0 -1 |  3 |
                    |  0 -1  1 |  4 |

		R2-R1	    |  1  1  1 | 11 |
		---->	    |  0 -1 -2 | -8 |
                    |  0 -1  1 |  4 |

		R3-R1	    |  1  1  1 | 11 |
		----->	    |  0 -1 -2 | -8 |
                    |  0  0  3 | 12 |

		R3/3	    |  1  1  1 | 11 |
		---->	    |  0 -1 -2 | -8 |
                    |  0  0  1 |  4 |

        R2+2*R3 	|  1  1  1 | 11 |
		------>     |  0 -1  0 |  0 |
                    |  0  0  1 |  4 |

		R2/-1	    |  1  1  1 | 11 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

		R1-R3	    |  1  1  0 |  7 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

		R1-R2	    |  1  0  0 |  7 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

        Result	    x = 7
		----->	    y = 0
                    z = 4
                    x  y  z   res
                    |  1  1  1 | 11 |
                    |  1  0 -1 |  3 |
                    |  0 -1  1 |  4 |

		R2-R1	    |  1  1  1 | 11 |
		---->	    |  0 -1 -2 | -8 |
                    |  0 -1  1 |  4 |

		R3-R1	    |  1  1  1 | 11 |
		----->	    |  0 -1 -2 | -8 |
                    |  0  0  3 | 12 |

		R3/3	    |  1  1  1 | 11 |
		---->	    |  0 -1 -2 | -8 |
                    |  0  0  1 |  4 |

        R2+2*R3 	|  1  1  1 | 11 |
		------>     |  0 -1  0 |  0 |
                    |  0  0  1 |  4 |

		R2/-1	    |  1  1  1 | 11 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

		R1-R3	    |  1  1  0 |  7 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

		R1-R2	    |  1  0  0 |  7 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

        Result	    x = 7
		----->	    y = 0
                    z = 4
                    x  y  z   res
                    |  1  1  1 | 11 |
                    |  1  0 -1 |  3 |
                    |  0 -1  1 |  4 |

		R2-R1	    |  1  1  1 | 11 |
		---->	    |  0 -1 -2 | -8 |
                    |  0 -1  1 |  4 |

		R3-R1	    |  1  1  1 | 11 |
		----->	    |  0 -1 -2 | -8 |
                    |  0  0  3 | 12 |

		R3/3	    |  1  1  1 | 11 |
		---->	    |  0 -1 -2 | -8 |
                    |  0  0  1 |  4 |

        R2+2*R3 	|  1  1  1 | 11 |
		------>     |  0 -1  0 |  0 |
                    |  0  0  1 |  4 |

		R2/-1	    |  1  1  1 | 11 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

		R1-R3	    |  1  1  0 |  7 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

		R1-R2	    |  1  0  0 |  7 |
		----->	    |  0  1  0 |  0 |
                    |  0  0  1 |  4 |

        Result	    x = 7
		----->	    y = 0
                    z = 4
12345678901234567890123456890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567
*/
